
import requests

#定义员工管理类
class IhrmEmpApi(object):
    #定义 添加员工 的方法
    @classmethod
    def add_emp(cls,header,req_data):
        resp = requests.post(url="http://192.168.118.143:8000/api/sys/user",
                             headers=header,json=req_data)
        return resp


    # 定义 查询员工 的方法
    @classmethod
    def search_emp(cls,emp_id,header):
        resp = requests.get(url="http://192.168.118.143:8000/api/sys/user/"+emp_id,headers=header)
        return resp


    # 定义 修改员工 的方法
    @classmethod
    def modify_emp(cls,emp_id,header,req_data):
        resp = requests.put(url="http://192.168.118.143:8000/api/sys/user/" + emp_id,
                            headers=header,json=req_data)
        return resp


    # 定义 删除员工 的方法
    @classmethod
    def del_emp(cls, emp_id, header):
        resp = requests.get(url="http://192.168.118.143:8000/api/sys/user/" + emp_id, headers=header)
        return resp

if __name__ == '__main__':
    # 类方法：可以通过类名.方法名() 就可以调用
    req_header={"Authorization": "Bearer 3fb93f20-d5be-4c4a-991a-2a6cdc8860d6"}
    add_json ={
        "username": "张四",
        "mobile": "17600000014",
        "workNumber": "12aa"}
    response = IhrmEmpApi.add_emp(req_header,add_json)
    print("添加员工：",response.json())

    emp_id = "1854105459540131840"
    response = IhrmEmpApi.search_emp(emp_id,req_header)
    print("查询员工",response.json())

    modify_json = {
        "id": 25,
        "mobile": "17600000005",
        "staffPhoto": None,
        "username": "李八",
        "timeOfEntry": "2024-11-04",
        "correctionTime": "2024-11-04T16:00:00.000Z",
        "departmentId": 11,
        "departmentName": "薪资管理部",
        "formOfEmployment": 1,
        "roleIds": []
    }
    response = IhrmEmpApi.modify_emp(emp_id,req_header,modify_json)
    print("修改员工：",response.json())

    response = IhrmEmpApi.del_emp(emp_id, req_header)
    print("删除员工", response.json())